package com.openyelp.apps;

import org.apache.oltu.oauth2.client.OAuthClient;
import org.apache.oltu.oauth2.client.URLConnectionClient;
import org.apache.oltu.oauth2.client.request.OAuthClientRequest;
import org.apache.oltu.oauth2.client.response.GitHubTokenResponse;
import org.apache.oltu.oauth2.common.OAuthProviderType;
import org.apache.oltu.oauth2.common.exception.OAuthProblemException;
import org.apache.oltu.oauth2.common.exception.OAuthSystemException;
import org.apache.oltu.oauth2.common.message.types.GrantType;

public class Appss {

	public static void main(String[] args) throws OAuthSystemException,
			OAuthProblemException {
		// TODO Auto-generated method stub
		/**
		 * FACEBOOK( "facebook", "https://graph.facebook.com/oauth/authorize",
		 * "https://graph.facebook.com/oauth/access_token"),
		 */
		OAuthClientRequest request = OAuthClientRequest
				.tokenLocation("http://cng1985.sturgeon.mopaas.com/api/access_token1.htm")
				.setGrantType(GrantType.AUTHORIZATION_CODE).setClientId("ada")
				.setClientSecret("client-secret")
				.setRedirectURI("http://cng1985.sturgeon.mopaas.com/api/t.htm")
				.setGrantType(GrantType.AUTHORIZATION_CODE)
				.setCode("a").buildQueryMessage();

		System.out.println(request.getLocationUri());
		// create OAuth client that uses custom http client under the hood
		OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());

		// Facebook is not fully compatible with OAuth 2.0 draft 10, access
		// token response is
		// application/x-www-form-urlencoded, not json encoded so we use
		// dedicated response class for that
		// Custom response classes are an easy way to deal with oauth providers
		// that introduce modifications to
		// OAuth 2.0 specification
		GitHubTokenResponse oAuthResponse = oAuthClient.accessToken(request,
				GitHubTokenResponse.class);

		String accessToken = oAuthResponse.getAccessToken();
		System.out.println(accessToken);
		Long expiresIn = oAuthResponse.getExpiresIn();
	}

}
